﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestProject1 {
    public class TestUtils {

        public static string RepeateTest(int num, Action action, string testInfo="", bool printInfo=true) {
            if(action == null) return "测试活动不可为空";
            Stopwatch stopwatch = Stopwatch.StartNew();
            stopwatch.Start();
            for(int i=0; i<num; i++) {
                action();
            }
            stopwatch.Stop();
            string info = String.Format($"{testInfo}  {num}次共耗时{stopwatch.ElapsedMilliseconds}ms,单次耗时{stopwatch.ElapsedMilliseconds/(float)num}ms");
            if(printInfo) Console.WriteLine(info);
            return info;
        }
    }
}
